package backend.service.admin;

import backend.model.admin.Shift;
import backend.service.base.DBModelServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ShiftServiceImpl extends DBModelServiceImpl<Shift> implements ShiftService {

    @Override
    public Class<Shift> getEntityClass() {
        return Shift.class;
    }

    @Override
    public List<Shift> findAllShifts() {
        return dbModelDao.findByNamedQuery("findAllShifts");
    }

    @Override
    public List<Shift> findAllActiveShifts() {
        return dbModelDao.findByNamedQuery("findAllActiveShifts");
    }

    @Override
    public Shift findShiftByName(String name) {
        List<Shift> occupationsByName = dbModelDao.findByNamedQueryAndParams("findShiftByName", new String[]{"name"}, new Object[]{name});
        assert occupationsByName.size() <= 1;
        if (occupationsByName.size() == 1) {
            return occupationsByName.get(0);
        }
        return null;
    }
}
